package com.ylbh.modules.shoppingcoupon.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.ylbh.common.annotation.SysLog;
import com.ylbh.common.pojo.goods.dto.GoodsClassDTO;
import com.ylbh.common.pojo.shoppingcoupon.dto.QueryCouponGoodsDTO;
import com.ylbh.common.pojo.shoppingcoupon.dto.ShoppingCouponDTO;
import com.ylbh.common.pojo.shoppingcoupon.vo.AddCouponGoodsListVO;
import com.ylbh.common.utils.CommonResult;
import com.ylbh.common.utils.Ref;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.ylbh.modules.shoppingcoupon.entity.ShoppingCoupon;
import com.ylbh.modules.shoppingcoupon.service.ShoppingCouponService;
import com.ylbh.common.utils.PageUtils;
import com.ylbh.common.utils.R;

/**
 * 商城优惠券
 * @author czx
 * @date 2019-10-30 13:52:37
 */
@RestController
@RequestMapping("shopping/coupon")
public class ShoppingCouponController {

    @Autowired
    private ShoppingCouponService shoppingCouponService;

    @GetMapping("/queryCouponList")
    @ApiOperation("商城优惠券列表信息")
//    @RequiresPermissions("shopping:coupon:queryCouponList")
    public CommonResult queryCouponList(ShoppingCouponDTO shoppingCouponDTO){
        PageUtils page = shoppingCouponService.queryCouponList(shoppingCouponDTO);

        return Ref.ok(page);
    }


    /**
     * 信息
     */
    @ApiOperation("查询商城优惠券详情")
    @GetMapping("/getCouponInfoById/{id}")
//    @RequiresPermissions("shopping:coupon:getCouponInfoById")
    public CommonResult getCouponInfoById(@PathVariable("id") String id){
		ShoppingCoupon shoppingCoupon = shoppingCouponService.getCouponInfoById(id);
        return Ref.ok(shoppingCoupon);
    }

    @SysLog("新增商品优惠券")
    @ApiOperation("新增商品优惠券")
    @PostMapping("/addCoupon")
//    @RequiresPermissions("shopping:coupon:addCoupon")
    public CommonResult addCoupon(@RequestBody ShoppingCoupon shoppingCoupon){
		shoppingCouponService.addCoupon(shoppingCoupon);

        return Ref.ok();
    }

    @SysLog("修改商城优惠券信息")
    @ApiOperation("修改商城优惠券信息")
    @PostMapping("/modifyCouponById")
//    @RequiresPermissions("shopping:coupon:modifyCouponById")
    public CommonResult modifyCouponById(@RequestBody ShoppingCoupon shoppingCoupon){
		shoppingCouponService.modifyCouponById(shoppingCoupon);

        return Ref.ok();
    }

    /**
     * 删除
     */
    @SysLog("删除商城优惠券")
    @ApiOperation("删除商城优惠券")
    @PostMapping("/removeCouponByIds")
//    @RequiresPermissions("shopping:coupon:removeCouponByIds")
    public CommonResult removeCouponByIds(@RequestBody String[] ids){
		shoppingCouponService.removeCouponByIds(Arrays.asList(ids));
        return Ref.ok();
    }

    @ApiOperation("根据类型查询分类")
    @GetMapping("queryClass/{type}")
    public CommonResult queryClass(@PathVariable Integer type) {
        List<GoodsClassDTO> list = shoppingCouponService.queryClass(type);
        return Ref.ok(list);
    }

    @ApiOperation("根据类型和id查询商品")
    @GetMapping("queryGoodsByTypeOrId")
    public CommonResult queryGoodsByTypeOrId(QueryCouponGoodsDTO queryCouponGoodsDTO) {
        PageUtils list = shoppingCouponService.queryGoodsByTypeOrId(queryCouponGoodsDTO);
        return Ref.ok(list);
    }

    @SysLog("商城优惠券启用与关闭")
    @ApiOperation("商城优惠券启用与关闭")
    @PostMapping("/modifyCouponStateById/{id}/{state}")
//    @RequiresPermissions("shopping:coupon:modifyCouponStateById")
    public CommonResult modifyCouponStateById(@PathVariable String id, @PathVariable Integer state) {
        shoppingCouponService.modifyCouponStateById(id, state);
        return Ref.ok();
    }
}
